/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.mess.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.thinkgem.jeesite.common.utils.CacheUtils;
import com.thinkgem.jeesite.modules.gen.dao.GenDataBaseDictDao;
import com.thinkgem.jeesite.modules.gen.entity.GenTable;
import com.thinkgem.jeesite.modules.sys.entity.Office;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.mess.entity.MessHall;
import com.thinkgem.jeesite.modules.mess.dao.MessHallDao;

/**
 * 菜谱管理Service
 * @author dby
 * @version 2020-08-20
 */
@Service
@Transactional(readOnly = true)
public class MessHallService extends CrudService<MessHallDao, MessHall> {


	@Autowired
	private MessHallDao MessHallDao;
	private MessHall messHall;


	public MessHall get(String id) {
		return super.get(id);
	}

	public List<MessHall> findList(MessHall messHall) {
		return super.findList(messHall);
	}

	public Page<MessHall> findPage(Page<MessHall> page, MessHall messHall) {
		return super.findPage(page, messHall);
	}

	@Transactional(readOnly = false)
	public void save(MessHall messHall) {
		super.save(messHall);
	}

	@Transactional(readOnly = false)
	public void delete(MessHall messHall) {
		super.delete(messHall);
	}


	/**
	 * 获取物理数据表列表
	 *
	 * @param messHall
	 * @return
	 */
	public List<MessHall> findTableList(MessHall messHall) {

		return MessHallDao.findTableList(messHall);
	}


//	/**
//	 * 获取物理数据表列表
//	 *
//	 * @param messHall
//	 * @return
//	 */
//	public List<Map<String, Object>> findMessTableList(MessHall messHall) {
//
//		List<Map<String, Object>> messTableList = MessHallDao.findMessTableList(messHall);
//
//		Map<String,String> map = new HashMap<>();
//
//		return messTableList;
//	}






	/**
	 * 获取物理数据表列表
	 *
	 * @param messHall
	 * @return
	 */
	public List<MessHall> findWeekList(MessHall messHall) {

		return MessHallDao.findWeekList(messHall);
	}





	public List<List> findHallList(MessHall messHall){
		List<MessHall> list = MessHallDao.findHallList(messHall);
		String[] str = new String[]{"breakfast","fruit","lunch","dinner","snock"};
		List<List> ser = new ArrayList<>();
		for(String res :str){
			List row =new ArrayList();
			row.add(getMealNameByCode(res));
			for(MessHall messHall1:list){
				row.add(messHall.fetchMealByCode(res));
			}
			ser.add(row);
		}
		return ser;
	}


	private String getMealNameByCode(String code){
		Map<String,String> map=new HashMap<>();
		map.put("breakfast","早餐");
		map.put("fruit","课间水果");
		map.put("lunch","午餐");
		map.put("dinner","晚餐");
		map.put("snock","加餐");
		return map.get(code);
	}



//	public List<List> findHallList(MessHall messHall){
//		List<MessHall> list=MessHallDao.findHallList(messHall);
//		String[] arr=new String[]{"breakfast","fruit","lunch","dinner","snock"};
//		List<List> res=new ArrayList<>();
//		for(String meal:arr){
//			List row=new ArrayList<>();
//			row.add(getMealNameByCode(meal));
//			for(MessHall messHall1:list){
//				row.add(messHall1.fetchMealByCode(meal));
//			}
//			res.add(row);
//		}
//		return res;
//	}





}